export default {
    data() {
        return {
        }
    },
    created() {
        if (this.$options.events) {
            Object.keys(this.$options.events).forEach(key => {
                let handler = this.$options.events[key]
                if (typeof handler === 'string') {
                    handler = this[handler]
                }
                this[key + '::handler'] = handler.bind(this)
                // console.log('on::handler', key)
                this.$nuxt.$on(key, this[key + '::handler'])
            })
        }
    },
    beforeDestroy() {
        if (this.$options.events) {
            Object.keys(this.$options.events).forEach(key => {
                // console.log('off::handler', key)
                this.$nuxt.$off(key, this[key + '::handler'])
            })
        }
    }
}
